﻿$(document).ready(function () {
	drawRestaurantGrid();
});

function drawRestaurantGrid() {
	var $gridRestaurants = $("#gridRestaurants").kendoGrid({
		dataSource: {
			type: "aspnetmvc-ajax",
			transport: {
				read: {
					url: "Customer/getRestaurantList"
				}
			},
			error: function (e) {
				document.write(e.xhr.responseText);
			},
			schema: {
				model: {
					fields: {
						Restaurantt: { type: "object" }
					}
				},
				data: "Data",
				total: "Total",
				errors: "Errors"
			},
			serverPaging: true,
			serverSorting: true,
			serverGrouping: true,
			serverFiltering: true
		},
		groupable: {
			messages: {
				empty: "Arrastre una columna para agrupar."
			}
		},
		height: 450,
		sortable: true,
		selectable: true,
		resizable: true,
		reorderable: true,
		filterable: true,
		pageable: {
			pageSize: 50,
			pageSizes: [10, 50, 100]
		},
		columns: [
			{ field: "Name", title: "Restaurante" },
            { field: "Address", title: "Direccion" },
            { field: "Telephone", title: "Telefono" },
            { field: "Points", title: "Calificacion" },
            { field: "Category.Description", title: "Categoria" },
            { field: "Open_time", title: "Abre", filterable: false },
			{ field: "Close_time", title: "Cierra", filterable: false },
            { field: "Open_days", title: "Dias", filterable: false },
            { field: "Description", title: "Descripcion", filterable: false }
		]
	}).data("kendoGrid");

	$gridRestaurants.element.delegate("tbody>tr", "dblclick", function () {
		var selectedRestaurant = $gridRestaurants.dataItem($gridRestaurants.select());

		getNewReserve(selectedRestaurant);
	});
}

function OpenAddReserveWindow() {
	var window = document.createElement('div');
	$(window).attr('id', 'addReserveWindow');

	$("#addReserveWindowContainer").append(window);

	var $addReserveWindow = $("#addReserveWindow").kendoWindow({
		content: "Customer/getPartials?partial=AddReserveWindow",
		width: 500,
		modal: true,
		title: 'Hacer reserva',
		visible: false,
		deactivate: function () {
			this.destroy();
		}
	}).data("kendoWindow");

	$addReserveWindow.open();
}